using System;
using System.Windows.Forms;
using SpellCenter.Core;

namespace SpellCenter.UI.FileChoosing
{
    public partial class FileChooserForm : Form
    {
        public FileChooserForm()
        {
            InitializeComponent();
            RegisterEvents();
        }

        /// <summary>
        /// Returns the full path to the CorpusConfig file
        /// </summary>
        public FilesInCorpusList Result
        {
            get { return _fileChooserConrol.Result; }
        }

        public string DictionaryFile
        {
            get { return _fileChooserConrol.DictionaryFile; }
        }

        private void RegisterEvents()
        {
            Load += Form_Load;
            _fileChooserConrol.Closing += FileChooserControl_Closing;
            _fileChooserConrol.Cancel += FileChooserControl_Cancel;
        }

        private void FileChooserControl_Cancel(object sender, EventArgs e)
        {
            Visible = false;
            _fileChooserConrol.Reset(null);
        }

        public event EventHandler Finished;

        protected void OnFinished(EventArgs e)
        {
            EventHandler handler = Finished;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        private void FileChooserControl_Closing(object sender, EventArgs e)
        {
            Hide();
            OnFinished(EventArgs.Empty);
        }

        private void Form_Load(object sender, EventArgs e)
        {
            Size = _fileChooserConrol.Size;
        }

        public void Reset(FilesInCorpusList config)
        {
            _fileChooserConrol.Reset(config);
        }
    }
}